package com.eoe.wiki.db.entity;

import java.io.File;
import java.util.UUID;

import com.eoe.wiki.Constants;
import com.eoe.wiki.utils.FileUtil;

import android.text.TextUtils;

public class WikiEntity extends DatabaseEntity {

	private String pageId;
	private String path;
	private String uri;
	private String displayTitle;
	private int version;
	private String content;
	private File wikiFile;
	
	public boolean isWikifileExist(){
		if(TextUtils.isEmpty(path)){
			return false;
		}
		if(wikiFile==null){
			wikiFile = new File(path);
		}
		return wikiFile.exists();
	}
	
	public String getWikiFileContent(){
		if(isWikifileExist()){
			content = FileUtil.getFileContent(wikiFile);
			return content;
		}
		return null;
	}
	
	public boolean saveWikiFile(String content){
		if(!FileUtil.isExternalStorageEnable()){
			return false;
		}
		String path = Constants.CACHE_DIR + File.separator + UUID.randomUUID().toString();
		boolean save = FileUtil.saveFile(content, path);
		if(save){
			this.path = path;
		}
		return save;
	}

	public String getPageId() {
		return pageId;
	}

	public void setPageId(String pageId) {
		this.pageId = pageId;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public String getDisplayTitle() {
		return displayTitle;
	}

	public void setDisplayTitle(String displayTitle) {
		this.displayTitle = displayTitle;
	}

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}
	
	
}
